
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class C1_11_6 {
    static int n, m;
    static int[] a;
    static long output;

    public static boolean ifOK(long x) {
        long sum = 0;
        int num = 1;
        for (int i = 0; i < n; i++) {
            if (sum + a[i] > x) {
                sum = 0;
                num++;
            }
            if (a[i] > x) {
                return false;
            }
            sum += a[i];
            if (num > m) {
                return false;
            }
        }
        output = x;
        return true;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String tmp = br.readLine();
        n = Integer.parseInt(tmp.split(" ")[0]);
        m = Integer.parseInt(tmp.split(" ")[1]);
        a = new int[n];
        long max = Long.MIN_VALUE;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(br.readLine());
            max = Math.max(max, a[i]);
            sum += a[i];
        }
        long left = max;
        long right = sum;
        while (left <= right) {
            long mid = (left + right) >>> 1;
            if (ifOK(mid)) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        System.out.println(output);
    }
}
